package ae.pcfc.etks.cld.to.web.constraints;



import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import org.springframework.web.multipart.MultipartFile;

/**
 * 
 * @author arosa
 *
 */
public class MaxFileSizeValidator implements ConstraintValidator<MaxFileSize, MultipartFile> {

	private Long maxFileSize;
	
	public void initialize(MaxFileSize constraintAnnotation) {
		maxFileSize = constraintAnnotation.maxFileSize();
	}

	public boolean isValid(MultipartFile value,
			ConstraintValidatorContext context) {
		return value==null || value.isEmpty() || (!value.getOriginalFilename().isEmpty() && value.getSize()>maxFileSize ? false : true); 
	}

}
